<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\UserNotification;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;

class UserNotificationController extends AdminBaseController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new UserNotification(), function (Grid $grid) {
            $grid->model()->orderByDesc('id');
            $grid->column('id')->sortable();
            $this->gridFilter($grid,'user_notifications');
            $grid->column('uid');
            $grid->column('type')->using(tt_user_notification_type('', true));
            $grid->column('amount')->numberFormat();
            $grid->column('read')->display(function () {
                return $this->read ? "已读" : "未读";
            });
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->disableActions();
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('uid')->width(3);
                $filter->equal('type')->select(tt_user_notification_type('', true))->width(3);

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new UserNotification(), function (Show $show) {
            $show->field('id');
            $show->field('uid');
            $show->field('type');
            $show->field('amount');
            $show->field('read');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new UserNotification(), function (Form $form) {
            $form->display('id');
            $form->text('uid');
            $form->text('type');
            $form->text('amount');
            $form->text('read');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
